/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.nju.software.greencreditsystem.util;

/**
 * 作者：韩天
 * 创建时间：2011-8-3
 * 类描述：读取原始数据的工具类,此类中调用XMLReader和ExcelReader读取数据
 */
public class DataReader {
    private XMLReader xmlReader = null;
    private ExcelReader excelReader = null;
    private String[] dataNames = null;
    
    public DataReader(String xmlFilePath, String excelFilePath, String[] dataNames) throws ExcelVersionErrorException{
        xmlReader = new XMLReader(xmlFilePath);
        excelReader = new ExcelReader(excelFilePath);
        this.dataNames = dataNames;
    }
    
    public double[] readData(){
        //datas数组用户存放要读取的数据，长度与所有数据的名称数组相同
        double[] datas = new double[dataNames.length];
        for(int i = 0; i<dataNames.length; i++){
            int[] location = xmlReader.getLocation(dataNames[i]);
            datas[i] = excelReader.readNumericCell(location[0], location[1], location[2]);
        }
        return datas;
    }
}
